<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试已结束</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <h1 class="text-center">考试已结束</h1>

        {% if error %}
            <p class="text-danger text-center">考试提交过程中发生错误: {{ error }}</p>
        {% else %}
            <p class="text-center">您已完成考试: <strong>{{ exam_name }}</strong></p>
            <p class="text-center">考试用时: <strong>{{ elapsed_seconds // 60 }} 分钟 {{ elapsed_seconds % 60 }} 秒</strong></p>
        {% endif %}

        <a href="{{ url_for('student_class', username=username, class_name=class_name) }}" class="btn btn-primary w-100">返回加入考试页面</a>
        <a href="{{ url_for('student_dashboard', username=username) }}" class="btn btn-secondary w-100 mt-2">返回主页面</a>

        <p class="text-center mt-4">页面将在 <span id="countdown">10</span> 秒后自动跳转到加入考试页面。</p>
    </div>

    <script>
        // 自动跳转倒计时功能
        var countdownElement = document.getElementById('countdown');
        var countdown = 10;
        var redirectUrl = "{{ url_for('student_class', username=username, class_name=class_name) }}";

        function updateCountdown() {
            countdown -= 1;
            countdownElement.textContent = countdown;

            if (countdown <= 0) {
                window.location.href = redirectUrl;
            }
        }

        setInterval(updateCountdown, 1000);
    </script>
</body>
</html>
